﻿using System;
using System.Collections.Generic;
using Mbs.Collections;

namespace Mbs.Messaging.Imp
{
    [Serializable]
    public class MessageListnerManager : ListnerManager<ISimpleMessageListner, MessageListnerType>, IMessageListnerManager, IMessageListner
    {
        public MessageListnerManager() { }
        public MessageListnerManager(Func<ICollection<ISimpleMessageListner>> listnersCreator) : base(listnersCreator) { }
        public static IMessageListnerManager Synchronized()
        {
            return new MessageListnerManager(() => new SyncList<ISimpleMessageListner>());
        }

        #region IMessageListner Members

        public void OnObserverAdding(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnObserverAdding(observer, topic, messageType));
        }

        public void OnObserverRemoving(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnObserverRemoving(observer, topic, messageType));
        }

        public void OnObserverAdded(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnObserverAdded(observer, topic, messageType));
        }

        public void OnObserverRemoved(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnObserverRemoved(observer, topic, messageType));
        }

        public void OnPreFilterAdding(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnPreFilterAdding(observer, topic, messageType));
        }

        public void OnPreFilterRemoving(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnPreFilterRemoving(observer, topic, messageType));   
        }

        public void OnPreFilterAdded(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnPreFilterAdded(observer, topic, messageType));   
        }

        public void OnPreFilterRemoved(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnPreFilterRemoved(observer, topic, messageType));   
        }

        public void OnFilterAdding(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnFilterAdding(observer, topic, messageType));   
        }

        public void OnFilterRemoving(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnFilterRemoving(observer, topic, messageType));   
        }

        public void OnFilterAdded(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnFilterAdded(observer, topic, messageType));   
        }

        public void OnFilterRemoved(object observer, string topic, Type messageType)
        {
            Foreach(item => item.OnFilterRemoved(observer, topic, messageType));   
        }

        public void OnSending(object sender, SendingEventArgs e)
        {
            Foreach(item => item.OnSending(sender,e));   
        }

        public void OnSent(object sender, MessageEventArgs e)
        {
            Foreach(item => item.OnSent(sender,e));   
        }

        public void OnReceivingException(object sender, ReceivingExceptionEventArgs e)
        {
            Foreach(item => item.OnReceivingException(sender, e));   
        }

        public void OnReceiving(object sender, ReceivingEventArgs e)
        {
            Foreach(item => item.OnReceiving(sender,e));   
        }

        public void OnReceived(object sender, MessageEventArgs e)
        {
            Foreach(item => item.OnReceived(sender,e));   
        }

        #endregion
    }
}
